From: Jasper St. Pierre Date: Fri, 1 Mar 2013 20:21:25 +0000 (-0500) Subject: layout: Prevent going into negatives with the pressure X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~4556 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=d4259fa8aa272727096ab66748d0d8e3287ce7f8;p=gnome-shell.git layout: Prevent going into negatives with the pressure We capped each event to 15px of travel, but we didn't do the same cap when subtracting events that were too old. --- diff --git a/js/ui/layout.js b/js/ui/layout.js index b178b53c8..bcc0dda6e 100644 --- a/js/ui/layout.js +++ b/js/ui/layout.js @@ -1296,19 +1296,16 @@ const PressureBarrier = new Lang.Class({ return Math.abs(event.dy); }, - _isBarrierEventTooOld: function(event) { - // Ignore all events older than this time - let threshold = this._lastTime - this._timeout; - return event.time < threshold; - }, - _trimBarrierEvents: function() { // Events are guaranteed to be sorted in time order from // oldest to newest, so just look for the first old event, // and then chop events after that off. let i = 0; + let threshold = this._lastTime - this._timeout; + while (i < this._barrierEvents.length) { - if (!this._isBarrierEventTooOld(this._barrierEvents[i])) + let [time, distance] = this._barrierEvents[i]; + if (time >= threshold) break; i++; } @@ -1316,7 +1313,8 @@ const PressureBarrier = new Lang.Class({ let firstNewEvent = i; for (i = 0; i < firstNewEvent; i++) { - this._currentPressure -= this._getDistanceAcrossBarrier(this._barrierEvents[i]); + let [time, distance] = this._barrierEvents[i]; + this._currentPressure -= distance; } this._barrierEvents = this._barrierEvents.slice(firstNewEvent); @@ -1362,8 +1360,10 @@ const PressureBarrier = new Lang.Class({ this._lastTime = event.time; this._trimBarrierEvents(); - this._barrierEvents.push(event); - this._currentPressure += Math.min(15, distance); + distance = Math.min(15, distance); + + this._barrierEvents.push([event.time, distance]); + this._currentPressure += distance; if (this._currentPressure >= this._threshold) this._trigger();